package com.zyl.blog.controller;/**
 * @author 14323
 * @date 2020/8/13 14:33
 */

import com.zyl.blog.pojo.Tag;
import com.zyl.blog.service.BlogService;
import com.zyl.blog.service.TagService;
import com.zyl.blog.vo.BlogQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @Description: TODO
 * @author: scott
 * @date: 2020年08月13日 14:33
 */
@Controller
public class TagShowController {

    @Autowired
    private BlogService blogService;

    @Autowired
    private TagService tagService;

    @GetMapping("/tags/{id}")
    public String tags(@PageableDefault(size = 5, sort = {"updateTime"}, direction = Sort.Direction.DESC) Pageable pageable,
            @PathVariable Long id, Model model) {

        List<Tag> tags = tagService.getTopTag(1000);

        if (id == -1) {
            id = tags.get(0).getId();
        }

        model.addAttribute("tags", tags);
        model.addAttribute("page", blogService.getBlogPage(id, pageable));
        model.addAttribute("activeTagid", id);

        return "tags";
    }
}
